new Vue({
    el: '#app',
    mixins: [Save],//组件配置文件，路径/utils/components.js
    data() {
        return {
            dataForm: {
                Coords:''
            },
            city: [],
            traceability_base:[],
            merchant:[],
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.init(); //初始化文件
         * 2.this.getData(); //仅修改时执行，根据BOM配置属性查询
         */
        this.getList();
    },
    methods: {
        getList() {//获取主数据
            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'merchant',
                    Condition: `Row_Status='2'`
                },
                type:'GET'
            }).then(data => {
               this.merchant = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })
            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'traceability_base',
                    Condition: `Row_Status='0'`
                },
                type:'GET'
            }).then(data => {
               this.traceability_base = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })
            $.ajax({
                url: absolutepath() + 'admin/data/dtree.json',
                type: 'GET',
                success: (data) => {
                    this.city = data;
                },
            })
        },
        changeCity(val) {//更新省/市 并切换地图中心点
            this.dataForm.ProvinceNumber = val ? (val.substring(0, 2) + '0000') : '';
            this.dataForm.CityNumber = val ? (val.substring(0, 4) + '00') : '';
            if (val) {
                let Province = this.city.filter(i=>i.code ==  this.dataForm.ProvinceNumber)[0];
                let City = Province.children.filter(i=>i.code ==  this.dataForm.CityNumber)[0];
                let County = City.children.filter(i=>i.code ==  this.dataForm.CountyNumber)[0];
                $.ajax({
                    url: `${BASE_URL3}/geocode/geo?key=${mapApiKey}&address=${encodeURIComponent(Province.name + City.name +  County.name)}`,
                    type: 'GET',
                    success: (res) => {
                        if (res.status == 1) {
                            const { location } = res.geocodes[0];
                            this.$refs.map.updateCenter(location.split(','));
                        }
                    }
                })
            }
        },
    }
})